const app = getApp()

const { pointApi } = require('../../../api/services/common/index')
Page({
  data: {
    name: '',
    params: {
      classId: '',
      troubleState: '',
    },
    dataList: [],
  },

  async getDataList() {
    const res = await pointApi(this.data.params)
    if (res.code != 200) {
      return app.toast(res.msg)
    }
    console.log(res)
    this.setData({ dataList: res.rows })
  },

  onSearch(e) {
    console.log(e.detail)
    this.setData({
      name: e.detail,
      'params.troubleState': e.detail,
    })
    this.setData({ listData: [] })
    this.getDataList()
  },

  onCancel() {
    this.setData({ 'params.troubleState': '', name: '' })
    this.getDataList()
  },

  handleItem(event) {
    let { item } = event.currentTarget.dataset
    let pages = getCurrentPages()
    console.log(item)
    let prevPage = pages[pages.length - 2]
    prevPage.setData({
      'item.troubleState': item.troubleState,
      'item.checkBasis': item.checkBasis,
      'item.troubleSite': item.troubleSite,
      'item.troubleSuggest': item.troubleSuggest,
    })

    prevPage.setData({
      troubleState: item.troubleState,
      checkBasis: item.checkBasis,
      troubleSite: item.troubleSite,
      troubleSuggest: item.troubleSuggest,
    })

    wx.navigateBack({
      delta: 1, //返回上一级页面
    })
  },

  onLoad: function (options) {
    console.log(options)
    this.setData({ 'params.classId': options.classId })
    this.getDataList()
  },
})
